package com.ec.system.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ec.core.common.core.base.BasePageVO;
import com.ec.core.common.utils.BeanUtilEx;
import com.ec.core.mybatis.utils.CorePageUtil;
import com.ec.core.secure.utils.SecureUtil;
import com.ec.system.modules.sys.dto.SysTenantParamDTO;
import com.ec.system.modules.sys.entity.SysTenantParam;
import com.ec.system.modules.sys.mapper.SysTenantParamMapper;
import com.ec.system.modules.sys.service.ISysTenantParamService;
import com.ec.system.modules.sys.vo.SysTenantParamVO;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class SysTenantParamServiceImpl extends ServiceImpl<SysTenantParamMapper, SysTenantParam>
        implements ISysTenantParamService {

    @Override
    public BasePageVO<SysTenantParamVO> listTenantParamByTenantId(String tenantId, Page page) {
        LambdaQueryWrapper<SysTenantParam> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(SysTenantParam::getTenantId, tenantId);
        Page<SysTenantParam> rst = super.page(page, wrapper);
        return CorePageUtil.buildPageResult(rst.getRecords(), (int) rst.getTotal(), SysTenantParamVO.class);
    }

    @Override
    public boolean addTenantParam(SysTenantParamDTO sysTenantParamDTO) {
        SysTenantParam sysTenantParam = new SysTenantParam();
        sysTenantParamDTO.setTenantId(SecureUtil.userTenantId().toString());
        BeanUtilEx.copyProperties(sysTenantParamDTO, sysTenantParam);
        return baseMapper.insert(sysTenantParam) == 1;
    }

    @Override
    public boolean updateTenantParam(SysTenantParamDTO sysTenantParamDTO) {
        SysTenantParam sysTenantParam = new SysTenantParam();
        BeanUtilEx.copyProperties(sysTenantParamDTO, sysTenantParam);
        return updateById(sysTenantParam);
    }

    @Override
    public boolean deleteTenantParam(String paramId) {
        return removeById(Long.parseLong(paramId));
    }
}




